package com.lemon.components.docs.mysql;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.lemon.components.ant.project.beans.TableInfo;
import com.lemon.components.ant.util.ConfigUtil;
import com.lemon.ui.codemaker.component.RecentlyFile;

import lombok.experimental.UtilityClass;

@UtilityClass
public class JTableDataForMybatisGen {
	
	private static List<TableInfo> tables = null;

	public String[] getColumns() {
		return new String[] {
				"名称", "编码"
			};
	}
	
	public String[][] getData(){
		tables = MysqlLocalTool.getTableInfo(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfoNoTable());
		String[][] rows = new String[tables.size()][2];
		for(int rownum = 0; rownum<tables.size(); rownum++) {
			TableInfo table = tables.get(rownum);
			rows[rownum][0] = table.getTableComment();
			rows[rownum][1] = table.getTableName();
		}
		return rows;
	}
	
	public String[][] getData(String column){
		if(tables == null)
			tables = MysqlLocalTool.getTableInfo(ConfigUtil.getInstance(RecentlyFile.configFilePath).getProjectInfoNoTable());
		String[][] rows = new String[tables.size()][2];
		int selected = 0;
		for(int rownum = 0; rownum<tables.size(); rownum++) {
			TableInfo table = tables.get(rownum);
			if(StringUtils.isNotBlank(column) && table.getTableName().indexOf(column)>=0) {
				rows[selected][0] = table.getTableComment();
				rows[selected][1] = table.getTableName();
				selected++;
			}
		}
		return rows;
	}
}
